﻿using System;
using System.Collections.Generic;
using System.Data.Objects.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoccaStore.Data.Entity.Model;

namespace RoccaStore.Data.Entity.Entities
{
    public class FileSendEntities : EntitiesBase<RoccaStoreEntities>, IFileSendRepository
    {
        public FileSend GetByID(int id)
        {
            return Context.FileSend.Include("Slug").SingleOrDefault(f => f.ID == id);
        }

        public List<FileSend> GetBySlug(string slug)
        {
            return Context.FileSend.Include("Slug").Where(f => f.Slug.Name.Equals(slug)).ToList();
        }

        public int Save(FileSend sendInfo)
        {
            try
            {
                if (sendInfo.ID == 0)
                    Context.FileSend.Add(sendInfo);

                Context.SaveChanges();
                return sendInfo.ID;
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
